<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 100的求和————函数写法
        function sum() {
            let result = 0;
            for (let i = 0; i <= 100; i++) {
                result = result + i;
            }
            console.log(result);
        }
        sum();




        //函数的求和——————for循环写法

        let sum = null;//声明一个空变量
        for (let i = 0; i < 101; i++) {
            // console.log(i); //1. 遍历了1-100的每个数
            sum = sum + i; // 空值累加遍历的每个值
        }
        console.log(sum);//打印累加数据









        // 倒遍历求和写法
        console.log('----------100 以内的整数倒着遍历求和-------------');
        let num = null;
        for (let i = 100; i > 0; i--) {
            num = num + i;
        }
        console.log(num);

    </script>
</body>

</html>